package com.gzy.rpsm_admin.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzy.rpsm_admin.mapper.BuildingMapper;
import com.gzy.rpsm_admin.mapper.FloorMapper;
import com.gzy.rpsm_admin.mapper.RoomMapper;
import com.gzy.rpsm_admin.pojo.Floor;
import com.gzy.rpsm_admin.pojo.PageResult;
import com.gzy.rpsm_admin.pojo.Room;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoomServiceImpl implements RoomService{
    @Autowired
    RoomMapper roomMapper;
    @Autowired
    FloorMapper floorMapper;
    @Autowired
    BuildingMapper buildingMapper;

    @Override
    public PageResult<Room> pageOfRoom(Integer current, Integer size, String number) {
        PageHelper.startPage(current,size);
        Page<Room> rooms = roomMapper.findAllRoom(number);
        rooms.stream().forEach(room -> {
            Floor floor = floorMapper.queryById(room.getRoom_floor_id());
            room.setFloor_number(floor.getFloor_number().intValue());
            room.setBuilding_name(buildingMapper.queryById(floor.getBelong_building()));
        });
        return PageResult.restPage(rooms);
    }
}
